package com.mc.moring.util;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.view.Display;


public class DensityUtil {
    public  float density;
    private static DensityUtil densityUtil;

    public static DensityUtil getInstance(){
        if (densityUtil==null){
            densityUtil = new DensityUtil();
        }
        return densityUtil;
    }

    public DensityUtil() {
        density = Resources.getSystem().getDisplayMetrics().density;
    }




    public  int dip2px(float dpValue) {
        return (int) (0.5f + dpValue * density);
    }


    public  float px2dip(int pxValue) {
        return (pxValue / density + 0.5f);
    }



    public  int sp2px(float spValue) {
        return (int) (spValue * density + 0.5f);
    }


    public  int px2sp(float pxValue) {
        return (int) (pxValue / density + 0.5f);
    }



    public float getDimension(Context context, int id){
        return context.getResources().getDimension(id);
    }


    public int getDimensionPixelSize(Context context,int id){
        return context.getResources().getDimensionPixelSize(id);
    }


    public int getDimensionPixelOffset(Context context,int id){
        return context.getResources().getDimensionPixelOffset(id);
    }

    public static int getScreenWidth(Activity context){
        Display display = context.getWindowManager().getDefaultDisplay();	//获得默认（本地）的显示设备
        int screen_width = display.getWidth();
        return screen_width;
    }

}